cmake_minimum_required(VERSION 3.8)
project(video_det_camera)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# Find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(cv_bridge REQUIRED)
find_package(image_transport REQUIRED)
find_package(std_msgs REQUIRED)

# Find OpenCV with specific components
find_package(OpenCV REQUIRED COMPONENTS core imgproc imgcodecs highgui videoio)

# Set OpenCV variables if not found by find_package
if(NOT OpenCV_FOUND)
  # Try to use pkg-config
  find_package(PkgConfig REQUIRED)
  pkg_check_modules(OpenCV REQUIRED opencv4)
  set(OpenCV_INCLUDE_DIRS ${OpenCV_INCLUDE_DIRS})
  set(OpenCV_LIBS ${OpenCV_LIBRARIES})
endif()

# Print OpenCV information for debugging
message(STATUS "OpenCV version: ${OpenCV_VERSION}")
message(STATUS "OpenCV libraries: ${OpenCV_LIBS}")
message(STATUS "OpenCV include dirs: ${OpenCV_INCLUDE_DIRS}")

# Include directories
include_directories(include)

# Create camera node executable
add_executable(camera_node src/camera_node.cpp)
ament_target_dependencies(camera_node
  rclcpp
  sensor_msgs
  cv_bridge
  image_transport
  std_msgs
)
target_link_libraries(camera_node ${OpenCV_LIBS})

# Create video detection node executable
add_executable(video_det_node src/video_det_node.cpp)
ament_target_dependencies(video_det_node
  rclcpp
  sensor_msgs
  cv_bridge
  image_transport
  std_msgs
)
target_link_libraries(video_det_node ${OpenCV_LIBS})

# Install executables
install(TARGETS
  camera_node
  video_det_node
  DESTINATION lib/${PROJECT_NAME}
)

# Install launch files
install(DIRECTORY
  launch
  DESTINATION share/${PROJECT_NAME}
)

# Install config files
install(DIRECTORY
  config
  DESTINATION share/${PROJECT_NAME}
)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package() 